package model;

public class Map {
	RealTile[][] realTile;
	
	static RealTile[][] testTile;

	public Map(RealTile[][] realTile)
	{
		this.realTile = realTile;
	}

	//gets adjacent tiles by getting all the tiles from tile.location-dx
	//to tile.location + dx. The same for dy. If tile goes out of the map
	//it returns with null.
	public RealTile[][] getAdjacentTiles(RealTile tile, int dx, int dy)
	{
		
		int dxLength = 2*Math.abs(dx);
		int dyLength = 2*Math.abs(dy);
		int xTile = tile.getX();
		int yTile = tile.getY();
		RealTile[][] newTile = new RealTile[dxLength+1][dyLength+1];
		
		//logic for getting the coordinates translated. if below dx or dy then it
		//is subtracted a right amount, if above dx or dy then it is added the right amount
		for(int i = 0; i <= dxLength; i++)
		{
			for(int j = 0; j <= dyLength; j++)
			{
				int xTemp = xTile - (dx - i);
				int yTemp = yTile - (dy - j);
				try
				{
					newTile[i][j] = realTile[xTemp][yTemp];
				}
				catch(ArrayIndexOutOfBoundsException e)
				{
					
				}
			}
		}
		
		return newTile;
	}
	
	public RealTile[][] getRealTile() {
		return realTile;
	}

	public void setRealTile(RealTile[][] realTile) {
		this.realTile = realTile;
	}
	
	public RealTile getRealTile(Location location)
	{
		try
		{
			return realTile[location.getX()][location.getY()];
		}
		catch(ArrayIndexOutOfBoundsException e)
		{
			return null;
		}
	}
}